﻿using System.Collections.Generic;
using Felbot.Interaction;
using Felbot.Interface.Users;
using Felbot.Profiles;
using Felbot.Properties;

namespace Felbot.Scripting.ScriptSupport {
    public static class Common {
        public static string Trigger {
            get {
                return ProfileControl.Global.GetSetting("Commands", "Trigger").ToString("!");
            }
        }

        public static string Version {
            get {
                return Resources.Version;
            }
        }

        public static string FormatListAsString<T>(List<T> list) {
            List<string> slist = new List<string>();
            foreach (T item in list)
                slist.Add(item.ToString());
            return FormatListAsString(slist);
        }

        public static string FormatListAsString(List<string> list) {
            if (list.Count == 0)
                return null;
            else if (list.Count == 1)
                return list[0] + " and " + list[1];
            else
                return string.Join(", ", list.ToArray(), 0, list.Count - 1) + ", and " + list[list.Count - 1];
        }

        public static XmlEntry GetUserEntry(string username, Profile profile) {
            return GetUserEntry(frmProfile.GetForm(profile).Channel.GetUser(username));
        }

        public static XmlEntry GetUserEntry(ChannelUser name) {
            return UserEntryControl.GetCumulativeEntry(name);
        }
    }
}
